<?php

namespace App\Customer\Controller;


use App\Customer\Model\CaseModel;
use EchoPHP\Http\Request;
use App\Customer\Model\Operator as Opr;

class Operator extends Controller {

    /**
     * 个人首页日历
     * @param Request $request
     * @return \EchoPHP\Http\Response\JsonResponse
     * @throws \Exception
     */
    public function getMonthTasks(Request $request) {
        $date = $request->getParam('date/s');//任务日期，标准时间格式，定位到年月
        $subId = $request->getParam('subid/d', 0);
        if (empty($subId) || empty($date)) {
            return $this->json([
                'status' => false,
                'message' => '参数出錯！'
            ]);
        }

        //校验subid和caseid是否属于该用户
        $hrUid = $this->getEhireHruid();
        $subIds = $this->getSubIds();
        $caseModel = new CaseModel();
        $checkResult = $caseModel->checkSubIdByHrUid($subIds, $subId);

        if (!$checkResult) {
            return $this->json([
                'status' => false,
                'message' => '参数出錯！'
            ]);
        }

        $oprModel = new Opr();
        $waitCount = $oprModel->getMonthTasks($date, $subId, $hrUid);
        return $this->json(['status' => true, 'message' => '获取成功', 'waitcount' => $waitCount]);
    }

    /**
     * 个人首页报表数据
     * @param Request $request
     * @return \EchoPHP\Http\Response\JsonResponse
     * @throws \Exception
     */
    public function getReportInfo(Request $request) {
        $date = $request->getParam('date', '');
        $subId = $request->getParam('subid/d', 0);
        if (empty($subId) || empty($date)) {
            return $this->json([
                'status' => false,
                'message' => '参数出錯！'
            ]);
        }
        //校验subid和caseid是否属于该用户
        $hrUid = $this->getEhireHruid();
        $subIds = $this->getSubIds();
        $caseModel = new CaseModel();
        $checkResult = $caseModel->checkSubIdByHrUid($subIds, $subId);
        if (!$checkResult) {
            return $this->json([
                'status' => false,
                'message' => '参数出錯！'
            ]);
        }

        $oprModel = new Opr();
        $reportList = $oprModel->getReportInfo($subId, $date, $hrUid);
        return $this->json(['status' => true, 'message' => '获取成功', 'reportlist' => $reportList]);
    }
}